/*
 * @Author: muuzi@163.com muuzi@163.com
 * @Date: 2024-12-04 22:55:50
 * @LastEditors: muuzi@163.com muuzi@163.com
 * @LastEditTime: 2024-12-15 21:56:33
 * @FilePath: /mp-wechat/mock/user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// mock/user.ts

import { resultSuccess } from "./_util"

const createUserList = () => {
    return [
        {
            userId: 1,
            avatar: 'https://pic1.zhimg.com/80/v2-083faf550543c1e9f134b56b3322ee3c_720w.webp',
            username: 'admin',
            password: '123456789',
            desc: '下船不谈船里事',
            roles: ['平台管理员'],
            buttons: ['cuser.detail'],
            routes: ['home'],
            token: 'Admin Token',
            openId:'123'
        },
        {
            userId: 2,
            avatar: 'https://pic1.zhimg.com/80/v2-e1427f6a21122ac163ff98d24f55d372_720w.webp',
            username: 'system',
            password: '123456789',
            desc: '旧人不谈近况，新人不讲过往',
            roles: ['系统管理员'],
            buttons: ['cuser.detail', 'cuser.user'],
            routes: ['home'],
            token: 'Admin Token',
             openId:'123456'
        }
    ]
}
export default [
    // 用户登录接口
    {
        url: '/auth/login',
        method: 'post',
        response: ({ body }: any) => {
            // 获取请求体携带过来的用户名与密码
            const { username, password,grantType,openId } = body
            // 调用获取用户信息函数，用于判断是否有此用户
            const checkUser = createUserList().find(
                (item) => {
                    if(grantType ==='wechat'){
                        return item.openId === openId
                    }else{
                        return item.username === username && item.password === password
                    }
                }
            )
            // 没有用户则返回失败信息
            if (!checkUser) {
                return {
                    code: 201,
                    data: {
                        msg: grantType ==='wechat'?'未绑定手机号':'账号或者密码不正确'
                    }
                }
            }
            // 如果有返回成功信息
            const { token } = checkUser
            return resultSuccess({token})
        }
    },
    // 获取用户信息接口
    {
        url: '/auth/getWechatOpenId',
        method: 'post',
        response: ({ body }: any) => {
            // 有就返回成功信息
            return resultSuccess({
                openId:'123'
            })
            
        }
    }
]
